// components/setting-num-buys/index.js
Component({
  options: {
    addGlobalClass: true
  },
  properties: {
    count:{type: Number, value: 1},
    stock:{type: Number, value: 5},
    lowest:{type: Number, value: 0},
  },
  data: {
    countData:0
  },
  lifetimes: {
    attached: function () {
      this.setData({countData:this.properties.count});
    }
  },
  methods: {
    addCount(e) {
      if(this.data.countData>=this.properties.stock)return;
      this.setData({countData:this.data.countData+1});
      this.triggerEvent('change',{count:this.data.countData});
    },
    delCount(e) {
      if(this.data.countData<=this.properties.lowest)return;
      this.setData({countData:this.data.countData-1});
      this.triggerEvent('change',{count:this.data.countData});
    },
    setCount(count) {
      this.setData({countData:count});
    },
    getCount() {
      return this.data.countData;
    },
  }
})
